<%@ page language="java" import="java.util.*,java.cn.baodao.*,java.cn.entity.*,java.jdbc.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'reginfo.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
   <%
   request.setCharacterEncoding("utf-8");
   String  name=request.getParameter("name");
  
   String  pass=request.getParameter("pwd");
    String  qq=request.getParameter("qq");
   String  wechat=request.getParameter("wx");
    String  stuno=request.getParameter("xh");
     String  sex=request.getParameter("sex");
   String  gradeid=request.getParameterValues("grade");
    if(name==null||name.equals("")){
    request.setAttribute(name, "用户名不能为空");
   request.getRequestDispatcher("register.jsp").forward(request, response);
   }else if(pass==null||pass.equals("")){
     request.setAttribute(pass, "密码名不能为空");
 	request.getRequestDispatcher("/register.jsp").forward(request, response);
   }else{
   //添加信息
   Student newstu = new Student(stuno, gradeid, name, sex, telephone, qq,
				wechat, city, address, pass);
   int insert=new MySqlStudentDaoImpl().add(newstu);
   if(insert>0){
   out.print("<script type='test/javascript'"+"alert("注册成功！")location.href='register.jsp'"+"</script>")   
   }else{
   	 request.setAttribute(name, "注册失败！");
      request.getRequestDispatcher("/register.jsp").forward(request, response);
   }
   }
    %>
  </body>
</html>
